package com.ocom.payconfig.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.ocom.common.AcpService;
import com.ocom.common.constant.PayConfigUrl;
import com.ocom.common.entity.card.EntityXfMerchantInfo;
import com.ocom.common.entity.card.EntityXfPointInfo;
import com.ocom.common.entity.payconfig.EntityDishesClass;
import com.ocom.common.entity.payconfig.EntityDishesInfo;
import com.ocom.common.entity.payconfig.EntityDishesPrice;
import com.ocom.common.entity.payconfig.EntityDishesWhite;
import com.ocom.common.enums.ResultEnum;
import com.ocom.common.request.payconfig.GetDishesInfoDetailListRequest;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import com.ocom.common.utils.StringUtil;
import com.ocom.common.vo.dishes.DishesInfoListVo;
import com.ocom.payconfig.service.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
public class DishesController {


    @Autowired
    private DishesClassService dishesClassService;

    @Autowired
    private DishesInfoService dishesInfoService;

    @Autowired
    private DishesPriceService dishesPriceService;

    @Autowired
    private DishesWhiteService dishesWhiteService;

    @Autowired
    private XfMerchantInfoService xfMerchantInfoService;

    @Autowired
    private XfPointInfoService xfPointInfoService;


    @Autowired
    private XfDeviceInfoService xfDeviceInfoService;

    //菜品分类列表
    @PostMapping(PayConfigUrl.Url_dishesClassList)
    public Result dishesClassList(Long comId,Integer merchId){
        List<EntityDishesClass> dishesClassList=dishesClassService.dishesClassList(comId,merchId);
        List<Map<String,Object>> mapList=new ArrayList<>();
        for (EntityDishesClass entityDishesClass : dishesClassList) {
            Map<String,Object> map=new HashMap<>();
            map.put("classId",entityDishesClass.getDishesClassId());
            map.put("merchId",entityDishesClass.getMerchId());
            map.put("parentId",entityDishesClass.getParentId());
            map.put("className",entityDishesClass.getDishesClassName());
            map.put("sort",entityDishesClass.getSort());
            map.put("quotaMin",entityDishesClass.getQuotaMin());
            map.put("quotaMax",entityDishesClass.getQuotaMax());
            map.put("remark",entityDishesClass.getRemark());
            mapList.add(map);
        }
        return ResultUtil.success(mapList);
    }

    @PostMapping(PayConfigUrl.Url_dishesClassOfCom)
    public Result dishesClassOfCom(@RequestParam("comId") Long comId){
        return ResultUtil.success(dishesClassService.dishesClassOfCom(comId));
    }


    @PostMapping(PayConfigUrl.Url_newDishesClass)
    public Result newDishesClass(@RequestBody JSONObject jsonObject){
        //如果parentId不等于0，查找上级分类是否存在：
        if (jsonObject.getInteger("parentId")!=0){
            EntityDishesClass entityDishesClass=dishesClassService.selectIsParentId(jsonObject.getLong("comId"),jsonObject);
            if (entityDishesClass==null){
                return ResultUtil.error(ResultEnum.Err_4062);
            }
        }

        EntityDishesClass entityDishesClass=dishesClassService.selectIsMerchId(jsonObject.getLong("comId"),jsonObject);
        if (entityDishesClass!=null){
            return ResultUtil.error(ResultEnum.Err_4063);
        }
        EntityDishesClass newDishesClass=new EntityDishesClass();
        newDishesClass.setComId(jsonObject.getInteger("comId"));
        newDishesClass.setMerchId(jsonObject.getInteger("merchId"));
        newDishesClass.setParentId(jsonObject.getInteger("parentId"));
        newDishesClass.setDishesClassName(jsonObject.getString("className"));
        newDishesClass.setSort(jsonObject.getInteger("sort"));
        newDishesClass.setRemark(jsonObject.getString("remark"));
        newDishesClass.setQuotaMax(jsonObject.getInteger("quotaMax"));
        newDishesClass.setQuotaMin(jsonObject.getInteger("quotaMin"));
        Date date=new Date();
        newDishesClass.setCreateTime(date);
        newDishesClass.setUpdateTime(date);
        newDishesClass.setCreateUserid(jsonObject.getInteger("userId"));
        if (dishesClassService.newDishesClass(jsonObject.getLong("comId"),newDishesClass)){
            return ResultUtil.success();
        }else {
            return ResultUtil.error(ResultEnum.Err_2016);
        }
    }

    //修改菜品分类（updateDishesClass）
    @PostMapping(PayConfigUrl.Url_updateDishesClass)
    public Result updateDishesClass(@RequestBody JSONObject jsonObject){
        EntityDishesClass entityDishesClass=dishesClassService.selectClassName(jsonObject.getLong("comId"),jsonObject);
        if (entityDishesClass!=null){
            return ResultUtil.error(ResultEnum.Err_4063);
        }
        EntityDishesClass newDishesClass=new EntityDishesClass();
        newDishesClass.setComId(jsonObject.getInteger("comId"));
        newDishesClass.setMerchId(jsonObject.getInteger("merchId"));
        newDishesClass.setParentId(jsonObject.getInteger("parentId"));
        newDishesClass.setDishesClassName(jsonObject.getString("className"));
        newDishesClass.setSort(jsonObject.getInteger("sort"));
        newDishesClass.setRemark(jsonObject.getString("remark"));
        newDishesClass.setQuotaMax(jsonObject.getInteger("quotaMax"));
        newDishesClass.setQuotaMin(jsonObject.getInteger("quotaMin"));
        newDishesClass.setDishesClassId(jsonObject.getInteger("dishesClassId"));
        Date date=new Date();
        newDishesClass.setUpdateTime(date);
        if (dishesClassService.updateDishesClass(jsonObject.getLong("comId"),newDishesClass)){
            return ResultUtil.success();
        }else {
            return ResultUtil.error(ResultEnum.Err_3026);
        }
    }

    //删除菜品分类
    @PostMapping(PayConfigUrl.Url_removeDishesClass)
    public Result removeDishesClass(Long comId,Integer merchId,Integer dishesClassId){
        EntityDishesClass entityDishesClass=dishesClassService.selectParentId(comId,merchId,dishesClassId);
        if (entityDishesClass!=null){
            return ResultUtil.error(ResultEnum.Err_4064);
        }

        EntityDishesInfo dishesInfo=dishesInfoService.selectRemoveDishesDishes(comId,merchId,dishesClassId);
        if (dishesInfo !=null){
            return ResultUtil.error(ResultEnum.Err_4068);
        }

        if (dishesClassService.removeDishesClass(comId,merchId,dishesClassId)){
            return ResultUtil.success();
        }else {
            return ResultUtil.error(ResultEnum.Err_3016);
        }
    }

    //获取下级菜品分类列表
    @PostMapping(PayConfigUrl.Url_getSubDishesClassList)
    public Result getSubDishesClassList(@RequestBody JSONObject jsonObject){
        String classIds="";
        if (jsonObject.getInteger("dishesClassId")==0){
           EntityDishesClass entityDishesClass=dishesClassService.selectDishesClassIds(jsonObject.getLong("comId"),jsonObject);
            classIds=entityDishesClass.getClassIds();
        }else if (jsonObject.getInteger("dishesClassId")>0){
            int i=0;
            String parentIds=jsonObject.getString("dishesClassId");
            classIds=parentIds;
            do {
                jsonObject.put("parentIds",parentIds);
                EntityDishesClass entityDishesClasss=dishesClassService.selectDishesClassIdEs(jsonObject.getLong("comId"),jsonObject);
                if (entityDishesClasss==null || entityDishesClasss.getClassIds()==null){
                    i=100;
                    break;
                }
                parentIds= entityDishesClasss.getClassIds();
                classIds=classIds+","+parentIds;
                i++;
            }while (i<100);
        }
        Map<String,Object> map=new HashMap<>();
        map.put("classIds",classIds);
        return ResultUtil.success(map);
    }

    @PostMapping(PayConfigUrl.Url_getAllDishes)
    public Result getAllDishes(@RequestParam("comId") Long comId){
        return ResultUtil.success(dishesInfoService.getAllDishes(comId));
    }
    //菜品列表（getDishesList）
    @PostMapping(PayConfigUrl.Url_getDishesList)
    public Result getDishesList(@RequestBody JSONObject jsonObject){
        List<String> classIds = null;
        if (StringUtils.isNotBlank( jsonObject.getString("classIds"))) {
            classIds = Arrays.asList( jsonObject.getString("classIds").split(","));
        }

        List<DishesInfoListVo>  dishesList=dishesInfoService.selectDishesInfoList(jsonObject.getLong("comId"), jsonObject.getInteger("merchId"), classIds, jsonObject.getString("dishesName"), jsonObject.getString("dishesCode"), jsonObject.getInteger("status"));

        PageInfo<DishesInfoListVo> getListRechargeRVoPageInfo = new PageInfo<>(dishesList);
        List<Integer> dishesIds=new ArrayList<>();
        for (DishesInfoListVo entityDishesInfo : getListRechargeRVoPageInfo.getList()) {
            dishesIds.add(entityDishesInfo.getDishesId());
        }
        List<EntityDishesPrice> priceList=dishesPriceService.selectDishesPriceList(jsonObject.getLong("comId"),jsonObject.getLong("merchId"),dishesIds);
        List<Map<String,Object>> mapList=new ArrayList<>();
        for (DishesInfoListVo entityDishesInfo : getListRechargeRVoPageInfo.getList()) {
            Map<String,Object> map=new HashMap<>();
            map.put("dishesId",entityDishesInfo.getDishesId());
            map.put("merchId",entityDishesInfo.getMerchId());
            map.put("dishesName",entityDishesInfo.getDishesName());
            map.put("dishesCode",entityDishesInfo.getDishesCode());
            map.put("photoUrl",entityDishesInfo.getPhotoUrl());
            map.put("dishesClassId",entityDishesInfo.getDishesClassId());
            map.put("dishesClassName",entityDishesInfo.getDishesClassName());
            map.put("quotaMin",entityDishesInfo.getQuotaMin());
            map.put("quotaMax",entityDishesInfo.getQuotaMax());
            map.put("sort",entityDishesInfo.getSort());
            map.put("status",entityDishesInfo.getStatus());
            map.put("remark",entityDishesInfo.getRemark());
            List<String> merchPrice=new ArrayList<>();
            List<String> pointPrice=new ArrayList<>();
            for (int i = 0; i < priceList.size(); i++) {
                if (entityDishesInfo.getDishesId().compareTo(priceList.get(i).getDishesId())==0){
                    if (priceList.get(i).getPointId()==0){
                        merchPrice.add(strPrice(priceList.get(i).getPriceMode(),priceList.get(i).getPrice()));
                    }else {
                        pointPrice.add(priceList.get(i).getPointName()+"："+strPrice(priceList.get(i).getPriceMode(),priceList.get(i).getPrice()));
                    }
                }
            }
            map.put("merchPrice",merchPrice);
            map.put("pointPrice",pointPrice);
            mapList.add(map);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("total",getListRechargeRVoPageInfo.getTotal());
        map.put("list",mapList);
        return ResultUtil.success(map);
    }

    private String strPrice(Byte priceMode,Integer price){
        //11：按重量（50g）；20：例；21：小；22：中；23：大
        String total_amount= AcpService.stringAmount(String.valueOf(price));
        if (priceMode==11){
            return total_amount+" / 两";
        }else if (priceMode==20){
            return total_amount+" / 例";
        }else if (priceMode==21){
            return total_amount+" / 小";
        }else if (priceMode==22){
            return total_amount+" / 中";
        }else if (priceMode==23){
            return total_amount+" / 大";
        }else if (priceMode==101){
            return total_amount+" / 按时长(元/分钟)";
        }else if (priceMode==100){
            return total_amount+" / 按次(元/次)";
        }
        return "";
    }

    //增加菜品（newDishes）
    @PostMapping(PayConfigUrl.Url_newDishes)
    public Result newDishes(@RequestBody JSONObject jsonObject){
        if (jsonObject.getInteger("dishesClassId")==0){
            return ResultUtil.error(ResultEnum.Err_4065);
        }else {
            EntityDishesClass entityDishesClass=dishesClassService.selectDishesClassId(jsonObject.getLong("comId"),jsonObject.getInteger("merchId"),jsonObject.getInteger("dishesClassId"));
            if (entityDishesClass==null){
                return ResultUtil.error(ResultEnum.Err_4066);
            }
        }
        EntityDishesInfo dishesInfo=dishesInfoService.selectDishesInfo(jsonObject.getLong("comId"),jsonObject);
        if (dishesInfo !=null){
            return ResultUtil.error(ResultEnum.Err_4067);
        }


        EntityDishesInfo entityDishesInfo=new EntityDishesInfo();
        entityDishesInfo.setComId(jsonObject.getLong("comId"));
        entityDishesInfo.setMerchId(jsonObject.getInteger("merchId"));
        entityDishesInfo.setDishesName(jsonObject.getString("dishesName"));
        entityDishesInfo.setDishesCode(jsonObject.getString("dishesCode"));
        entityDishesInfo.setPhotoUrl(jsonObject.getString("photoUrl"));
        entityDishesInfo.setDishesClassId(jsonObject.getInteger("dishesClassId"));
        entityDishesInfo.setQuotaMax(jsonObject.getInteger("quotaMax"));
        entityDishesInfo.setQuotaMin(jsonObject.getInteger("quotaMin"));
        if (jsonObject.get("sort")==null || jsonObject.getInteger("sort")==0){
            EntityDishesInfo sortMax=dishesInfoService.sortMax(jsonObject.getLong("comId"),jsonObject);
            if (sortMax==null){
                entityDishesInfo.setSort(10);
            }else {
                entityDishesInfo.setSort(sortMax.getSort()+10);
            }
        }else {
            entityDishesInfo.setSort(jsonObject.getInteger("sort"));
        }

        entityDishesInfo.setStatus(jsonObject.getByte("status"));
        entityDishesInfo.setRemark(jsonObject.getString("remark"));
        Date date=new Date();
        entityDishesInfo.setCreateTime(date);
        entityDishesInfo.setCreateUserid(jsonObject.getInteger("UserId"));
        entityDishesInfo.setUpdateTime(date);
        return ResultUtil.success(dishesInfoService.insertDishesInfo(jsonObject.getLong("comId"),entityDishesInfo));

    }

    //修改菜品
    @PostMapping(PayConfigUrl.Url_updateDishes)
    public Result updateDishes(@RequestBody JSONObject jsonObject){
        if (jsonObject.getInteger("dishesClassId")==0){
            return ResultUtil.error(ResultEnum.Err_4065);
        }else {
            EntityDishesClass entityDishesClass=dishesClassService.selectDishesClassId(jsonObject.getLong("comId"),jsonObject.getInteger("merchId"),jsonObject.getInteger("dishesClassId"));
            if (entityDishesClass==null){
                return ResultUtil.error(ResultEnum.Err_4066);
            }
        }
        EntityDishesInfo dishesInfo=dishesInfoService.selectUpdateDishes(jsonObject.getLong("comId"),jsonObject);
        if (dishesInfo !=null){
            return ResultUtil.error(ResultEnum.Err_4067);
        }
        EntityDishesInfo entityDishesInfo=new EntityDishesInfo();
        entityDishesInfo.setComId(jsonObject.getLong("comId"));
        entityDishesInfo.setMerchId(jsonObject.getInteger("merchId"));
        entityDishesInfo.setDishesName(jsonObject.getString("dishesName"));
        entityDishesInfo.setDishesCode(jsonObject.getString("dishesCode"));
        entityDishesInfo.setDishesClassId(jsonObject.getInteger("dishesClassId"));
        entityDishesInfo.setSort(jsonObject.getInteger("sort"));
        entityDishesInfo.setStatus(jsonObject.getByte("status"));
        entityDishesInfo.setRemark(jsonObject.getString("remark"));
        entityDishesInfo.setDishesId(jsonObject.getInteger("dishesId"));
        entityDishesInfo.setQuotaMax(jsonObject.getInteger("quotaMax"));
        entityDishesInfo.setQuotaMin(jsonObject.getInteger("quotaMin"));
        Date date=new Date();
        entityDishesInfo.setUpdateTime(date);
        dishesInfoService.updateDishesInfo(jsonObject.getLong("comId"),entityDishesInfo);
        updateDishesWhite(jsonObject);
        return ResultUtil.success();
    }

    //修改菜品图片（changeDishesPhoto）
    @PostMapping(PayConfigUrl.Url_changeDishesPhoto)
    public Result changeDishesPhoto(Long comId,Integer dishesId,String photoUrl){
        EntityDishesInfo entityDishesInfo=new EntityDishesInfo();
        entityDishesInfo.setDishesId(dishesId);
        entityDishesInfo.setPhotoUrl(photoUrl);
        if (dishesInfoService.updateDishesInfo(comId,entityDishesInfo)){
            return ResultUtil.success();
        }else {
            return ResultUtil.error(ResultEnum.Err_3014);
        }
    }

    //获取菜品定价表（getDishesPriceList）
    @PostMapping(PayConfigUrl.Url_getDishesPriceList)
    public Result getDishesPriceList(Long comId,Integer dishesId,Integer merchId){
        List<EntityDishesPrice> list=dishesPriceService.getDishesPriceList(comId,dishesId,merchId);
        List<Map<String,Object>> mapList=new ArrayList<>();
        for (EntityDishesPrice entityDishesPrice : list) {
            Map<String,Object> map=new HashMap<>();
            map.put("pointId",entityDishesPrice.getPointId());
            map.put("priceMode",entityDishesPrice.getPriceMode());
            map.put("price",entityDishesPrice.getPrice());
            mapList.add(map);
        }
        Map<String,Object> map=new HashMap<>();
        map.put("priceList",mapList);
        return ResultUtil.success(map);
    }


    //修改菜品白名单
    @PostMapping(PayConfigUrl.Url_updateDishesWhite)
    public Result updateDishesWhite(@RequestBody JSONObject jsonObject){
        Byte whiteState=0;
        if (jsonObject.getInteger("status")==2){
            whiteState=1;
        }else {
            Result result=getDishesPriceList(jsonObject.getLong("comId"),jsonObject.getInteger("dishesId"),jsonObject.getInteger("merchId"));
            if (result.getCode()==200){
                JSONObject objectList= JSON.parseObject(JSON.toJSONString(result.getData()),JSONObject.class);
                if (objectList.get("priceList")==null){
                    whiteState=1;
                }else {
                    whiteState=0;
                }
            }
        }
        dishesWhiteService.removeDishesWhite(jsonObject.getLong("comId"),jsonObject.getInteger("dishesId"),jsonObject.getInteger("merchId"));
        EntityDishesWhite entityDishesWhite=new EntityDishesWhite();
        entityDishesWhite.setComId(jsonObject.getLong("comId"));
        entityDishesWhite.setMerchId(jsonObject.getInteger("merchId"));
        entityDishesWhite.setDishesId(jsonObject.getInteger("dishesId"));
        entityDishesWhite.setState(whiteState);
        entityDishesWhite.setCreateTime(new Date());
        dishesWhiteService.insertDishesWhite(jsonObject.getLong("comId"),entityDishesWhite);
        Result result=getPointsByMerch(jsonObject.getLong("comId"),jsonObject.getInteger("merchId"));
        String strPoints="";
        if (result.getCode()==200){
            JSONObject parseObject=JSON.parseObject(JSON.toJSONString(result.getData()),JSONObject.class);
            strPoints=parseObject.getString("strPoints");
        }
       xfDeviceInfoService.updateMenuState(jsonObject.getLong("comId"),strPoints);
        return ResultUtil.success();
    }

    //商户绑定的消费点
    @PostMapping(PayConfigUrl.Url_getPointsByMerch)
    public Result getPointsByMerch(Long comId,Integer merchId){
        String strMerchs="";
        String strParentMerchs="";
        List<EntityXfPointInfo> pointList=null;
        if (merchId>0){
            strMerchs= String.valueOf(merchId);
            strParentMerchs=strMerchs;
            strMerchs=strMerchsV(comId,strParentMerchs);
            pointList=xfPointInfoService.selectPointList(comId,merchId,strMerchs);
        }else {
            EntityDishesClass entityDishesClass=dishesClassService.selectrMerchs(comId,merchId);
            if (entityDishesClass!=null && StringUtil.isNotEmpty(entityDishesClass.getStrMerchs())){
                strParentMerchs=entityDishesClass.getStrMerchs();
                strMerchs=strMerchsV(comId,strParentMerchs);
                pointList=xfPointInfoService.selectPointList(comId,merchId,strMerchs);
            }else {
                pointList=xfPointInfoService.selectPointListS(comId);
            }
        }

        String strPoints="";
        List<Map<String,Object>> mapList=new ArrayList<>();
        if (pointList!=null && pointList.size()>0){
            for (int i = 0; i < pointList.size(); i++) {
                if (i==0){
                    strPoints= String.valueOf(pointList.get(i).getPointId());
                }else {
                    strPoints=strPoints+","+pointList.get(i).getPointId();
                }
                Map<String,Object> map=new HashMap<>();
                map.put("pointId",pointList.get(i).getPointId());
                map.put("pointName",pointList.get(i).getPointName());
                mapList.add(map);
            }
            if (merchId==0){
                strPoints=strPoints+",0";
            }

        }else {
            if (merchId==0){
                strPoints="0";
            }else {
                strPoints="-1";
            }
        }
        Map<String,Object> map=new HashMap<>();
        map.put("pointList",mapList);
        map.put("strPoints",strPoints);
        return ResultUtil.success(map);
    }

    private String strMerchsV(Long comId,String strParentMerchs){
        String strMerchs=strParentMerchs;
        int i=0;
        do {
            EntityXfMerchantInfo entityXfMerchantInfo=xfMerchantInfoService.selectParentMerchs(comId,strParentMerchs);
            if (entityXfMerchantInfo==null || StringUtil.isEmpty(entityXfMerchantInfo.getStrParentMerchs())){
                return strMerchs;
            }else {
                strParentMerchs=entityXfMerchantInfo.getStrParentMerchs();
                strMerchs=strMerchs+","+strParentMerchs;
            }
            i++;
        }while (i<100);
        return strMerchs;
    }

    //保存菜品价格
    @PostMapping(PayConfigUrl.Url_setDishesPrice)
    public Result setDishesPrice(@RequestBody JSONObject jsonObject){
        EntityDishesPrice entityDishesPrice=dishesPriceService.selectPriceDishesInfo(jsonObject.getLong("comId"),jsonObject);
        if (entityDishesPrice==null){
            EntityDishesPrice dishesPrice=new EntityDishesPrice();
            dishesPrice.setComId(jsonObject.getLong("comId"));
            dishesPrice.setMerchId(jsonObject.getInteger("merchId"));
            dishesPrice.setPointId(jsonObject.getInteger("pointId"));
            dishesPrice.setDishesId(jsonObject.getInteger("dishesId"));
            dishesPrice.setPriceMode(jsonObject.getByte("priceMode"));
            dishesPrice.setPrice(jsonObject.getInteger("price"));
            Date date=new Date();
            dishesPrice.setCreateTime(date);
            dishesPrice.setCreateUserid(jsonObject.getInteger("UserId"));
            dishesPrice.setUpdateTime(date);
            if (!dishesPriceService.insertDishesPrice(jsonObject.getLong("comId"),dishesPrice)){
                return ResultUtil.error(ResultEnum.Err_4069);
            }
        }else {
            EntityDishesPrice dishesPrice=new EntityDishesPrice();
            dishesPrice.setId(entityDishesPrice.getId());
            dishesPrice.setPrice(jsonObject.getInteger("price"));
            if (!dishesPriceService.updateDishesPrice(jsonObject.getLong("comId"),dishesPrice)){
                return ResultUtil.error(ResultEnum.Err_4069);
            }
        }
        jsonObject.put("status",1);
        updateDishesWhite(jsonObject);
        return ResultUtil.success();
    }

    //移除菜品价格（removeDishesPrice）
    @PostMapping(PayConfigUrl.Url_removeDishesPrice)
    public Result removeDishesPrice(@RequestBody JSONObject jsonObject){
        if (!dishesPriceService.removeDishesPrice(jsonObject.getLong("comId"),jsonObject)){
            return ResultUtil.error(ResultEnum.Err_3016);
        }
        jsonObject.put("status",1);
        updateDishesWhite(jsonObject);
        return ResultUtil.success();
    }

    //重置菜品下传标志（dishesAllDownload）
    @PostMapping(PayConfigUrl.Url_dishesAllDownload)
    public Result dishesAllDownload(Long comId,Integer merchId){
        dishesWhiteService.removeDishesAllDownload(comId,merchId);
        List<EntityDishesPrice> list=dishesPriceService.getDishesAllDownload(comId,merchId);
        List<EntityDishesWhite> insertList=new ArrayList<>();
        for (EntityDishesPrice entityDishesPrice : list) {
            EntityDishesWhite entityDishesWhite=new EntityDishesWhite();
            entityDishesWhite.setComId(comId);
            entityDishesWhite.setMerchId(merchId);
            entityDishesWhite.setDishesId(entityDishesPrice.getDishesId());
            entityDishesWhite.setState((byte) 0);
            entityDishesWhite.setCreateTime(new Date());
            insertList.add(entityDishesWhite);
        }
        dishesWhiteService.insertDishesWhites(comId,insertList);
        Result result=getPointsByMerch(comId,merchId);
        String strPoints="";
        if (result.getCode()==200){
            JSONObject parseObject=JSON.parseObject(JSON.toJSONString(result.getData()),JSONObject.class);
            strPoints=parseObject.getString("strPoints");
        }
        xfDeviceInfoService.updateDishesAllDownload(comId,merchId,strPoints);
        return ResultUtil.success();
    }


    @PostMapping(PayConfigUrl.Url_getDishesInfoDetailList)
    public Result findByComIdAndDishesId(@RequestBody GetDishesInfoDetailListRequest request){
        return ResultUtil.success(dishesInfoService.findByComIdAndDishesId(request.getComId(), request.getDishesIds()));

    }
}
